export  default {
    //上传前操作
    beforeUpload(file) {
        const fileReader = new FileReader()
        fileReader.readAsDataURL(file)
        fileReader.onload = () => {
            //用于预览
            this.imgUrl = fileReader.result
        }
    },
    //点击文件列表中已上传的文件时的钩子
    handlePictureCardPreview(file) {
        this.imgUrl = file.url;
        console.log(this.imgUrl)
        this.dialogVisible = true;
    },
    HFhandleRemove() {
        this.imgUrl = ''
        this.file = null
    },
    HFhandleChangeImg(file, fileList) {
        const isImage = file.raw.type === "image/png" || "image/jpg" || "image/jpeg";
        const isLt2M = file.raw.size / 1024 / 1024 < 2;
        if (fileList.length > 0) {
            //单个覆盖上传
            this.HFfileList = [fileList[fileList.length - 1]]; // 这一步，是 展示最后一次选择的csv文件
            if (!isImage) {
                this.$message.error("只能上传图片!");
                return false;
            } else if (!isLt2M) {
                this.$message.error("上传图片大小不能超过 2Mb!");
                this.HFfileList = []
                return false;
            } else if (isLt2M && isImage) {
                this.file = file.raw;//待上传图片的url
            }
        }
        //预览
        var file = file.raw;
        var reader = new FileReader();
        var that = this;
        reader.readAsDataURL(file);
        reader.onload = function (e) {
            that.imgUrl = this.result;//上传前可预览图片路径
        };
    },
}